<template>
	<view class="region">
		<view class="flex benben-position-layout flex flex-wrap align-center wrongQuestion_flex_0"
			:style="{height:(88+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx'}">
			<view class='flex flex-wrap align-center justify-between flex-sub wrongQuestion_fd0_0'>
				<view class='flex flex-wrap align-center' @tap.stop="handleJumpDiy" data-type="back" data-url="1">
					<text class='fu-iconfont2  wrongQuestion_fd0_0_c0_c0'>&#xE794;</text>
				</view>
				<text class='wrongQuestion_fd0_0_c1'>城市切换</text>
				<view class='flex flex-wrap align-center wrongQuestion_fd0_0_c2'>
				</view>
			</view>
		
		</view>
		<view :style="{height: (88+StatusBarRpx)+'rpx'}"></view>
		<!-- 数据加载动画 start -->
		<fu-loading v-if="isShowLoading"></fu-loading>
		<block v-else>
			<!-- <view class="current">
				<view class="current-city">
					当前城市
				</view>
				<view class="city" @tap="selectCity(city)">
					<image src="/static/index/address.png"></image>
					<text>{{city}}</text>
				</view>
			</view>
			<view class="city-list">
				<u-index-list :scrollTop="scrollTop" active-color="#333">
					<view v-for="(item, index) in indexList" :key="index">
						<u-index-anchor :index="item.value" />
						<u-index-anchor :use-slot="true">
							<text class="anchor-text">{{item.value}}</text>
						</u-index-anchor>
						<view v-if="item.city">
							<view class="list-cell" v-for="(v, k) in item.city" :key="k" @tap="selectCity(v.name,v.lng,v.lat)">
								{{v.name}}
							</view>
						</view>
					</view>
				</u-index-list>
			</view> -->
			<view>
				<city-select @cityClick="cityClick" :formatName="formatName" :activeCity="activeCity" :hotCity="hotCity"
					:obtainCitys="obtainCitys" :isSearch="true" ref="citys"></city-select>
			</view>
		</block>
	</view>
</template>

<script>
	import citySelect from "@/components/city-select/city-select.vue"
	export default {
		data() {
			return {
				scrollTop: 0,
				indexList: [],
				city: '',
				isShowLoading: true,
				
				
				//需要构建索引参数的名称（注意：传递的对象里面必须要有这个名称的参数）
				formatName: 'city_name',
				//当前城市
				activeCity: {
					id: 1,
					city_name: '武汉'
				},
				//热门城市
				hotCity: [],
				//显示的城市数据
				obtainCitys: [
				]
			}
		},
		components: {
			citySelect
		},
		onPageScroll(e) {
			this.scrollTop = e.scrollTop;
		},
		onLoad() {
			this.regionListInfo();
		},
		onShow() {
			if (uni.getStorageSync('city')) {
				this.activeCity.city_name = uni.getStorageSync('city');
			}
			// this.activeCity.lat = uni.getStorageSync('defaultCity').latitude;
			// this.activeCity.lng = uni.getStorageSync('defaultCity').longitude;
		},
		methods: {
			regionListInfo() {
				this.$api.post(global.apiUrls.post6318893a73bb8, {

				}).then(res => {
					// console.log(res);
					if (res.data.code == 1) {
						this.isShowLoading = false;
						this.indexList = res.data.data.city_list;
						this.hotCity = res.data.data.hot_list;
						if (this.indexList.length > 0) {
							let indexlist = [];
							for(var i = 0; i < this.indexList.length; i++) {
								for(var k = 0; k < this.indexList[i].city_list.length; k++) {
									indexlist.push(this.indexList[i].city_list[k]);
								}
							}
							this.obtainCitys = indexlist
						}
					} else {
						this.$message.info(res.data.message);
					}
				})
			},
			cityClick(e) {
				// console.log(e);
				let address = {
					city: e.cityName || e.city_name || e.name
				};
				uni.$emit('changeCity', address);
				uni.navigateBack({
					delta: 1
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.region {
		.current {
			padding: 32rpx;
			background: #F5F6F7;

			.current-city {
				font-size: 28rpx;
				color: #666666;
				margin-bottom: 32rpx;
			}

			.city {
				padding: 10rpx 38rpx;
				background: #FFFFFF;
				display: inline-block;
				border-radius: 4rpx;

				image {
					width: 20rpx;
					height: 24rpx;
					vertical-align: middle;
					margin-right: 8rpx;
				}

				text {
					font-size: 24rpx;
				}
			}
		}

		.city-list {
			.list-cell {
				display: flex;
				box-sizing: border-box;
				width: 100%;
				padding: 10px 24rpx;
				overflow: hidden;
				color: #323233;
				font-size: 14px;
				line-height: 24px;
				background-color: #fff;
			}
		}

	}
	.wrongQuestion_fd0_0 {
		padding: 0rpx 32rpx 0rpx 32rpx;
		height: 88rpx;
	}
	
	.wrongQuestion_fd0_0_c0_c0 {
		font-size: 36rpx;
		font-weight: 500;
		color: #333;
		line-height: 36rpx;
	}
	
	.wrongQuestion_fd0_0_c1 {
		font-size: 36rpx;
		font-weight: 500;
		color: #333333;
		line-height: 50rpx;
	}
	
	.wrongQuestion_fd0_0_c2 {
		width: 36rpx;
		height: 36rpx;
	}
	
	.wrongQuestion_flex_0 {
		// background: url(https://app.ezsdcsm.com/images/23.png) no-repeat, transparent;
		width: 750rpx;
		height: 88rpx;
		overflow: hidden;
		z-index: 10;
		top: 0rpx;
		background-size: 100% auto !important;
		background-color: #fff;
	}
</style>
